// Loesung_von_Aufgabe_11.4_2_Sierpinski_Dreieck

void setup()
{
  size(600, 600);
}

void draw()
{
  background(255);
  dreieck(0, 600, 300, 0, 600, 600, 600, 600);
}

void dreieck(float x1, float y1, float x2, float y2, float x3, float y3, float b, float h)
{
  stroke(2);
  noFill();
  triangle(x1, y1, x2, y2, x3, y3);

  if (b > 1) // Vermeidung einer Endlosschleife
  {
    dreieck(x1+b/2, y1, x2+b/4, y2+h/2, x3, y3, b-b/2, h-h/2); // // verkleinertes Dreieck; unten rechts
    dreieck(x1, y1, x2-b/4, y2+h/2, x3-b/2, y3, b-b/2, h-h/2); // verkleinertes Dreieck; unten links
    dreieck(x1+b/4, y1-h/2, x2, y2, x3-b/4, y3-h/2, b-b/2, h-h/2); // verkleinertes Dreieck; oben mittig
  }
} 